home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume4 / conquer3 / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-06-16  |  55.9 KB

  1. Path: uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games
  2. From: games@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v04i043:  conquer3 - middle earth multi-player game (V3), Part02/08
  5. Message-ID: <2652@tekred.TEK.COM>
  6. Date: 16 Jun 88 21:35:56 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 1936
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted by: ihnp4!homxc!smile
  12. Comp.sources.games: Volume 4, Issue 43
  13. Archive-name: conquer3/Part02
  14.  
  15.  
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 2 (of 8)."
  24. # Contents:  combat.c npc.c
  25. # Wrapped by billr@saab on Thu Jun 16 09:39:56 1988
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f combat.c -a "${1}" != "-c" ; then 
  28.   echo shar: Will not over-write existing file \"combat.c\"
  29. else
  30. echo shar: Extracting \"combat.c\" \(24900 characters\)
  31. sed "s/^X//" >combat.c <<'END_OF_combat.c'
  32. X/*conquer : Copyright (c) 1988 by Ed Barlow.
  33. X *  I spent a long time writing this code & I hope that you respect this.
  34. X *  I give permission to alter the code, but not to copy or redistribute
  35. X *  it without my explicit permission.  If you alter the code,
  36. X *  please document changes and send me a copy, so all can have it.
  37. X *  This code, to the best of my knowledge works well,  but it is my first
  38. X *  'C' program and should be treated as such.  I disclaim any
  39. X *  responsibility for the codes actions (use at your own risk).  I guess
  40. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  41. X *                                                Ed
  42. X */
  43. X
  44. X#include "header.h"
  45. X#include "data.h"
  46. X
  47. X#define    MGKNUM    32        /* number of units possible in battle */
  48. X#define    ATKR    2
  49. X#define    DFND    1
  50. X
  51. Xextern    FILE    *fnews;
  52. Xextern    short    country;
  53. X
  54. Xshort    retreatside;    /* ATKR, DFND, or none (0) */
  55. Xshort    retreatx;    /* retreat x square */
  56. Xshort    retreaty;    /* retreat y square */
  57. X
  58. Xint    unit[MGKNUM];        /*armynum*/
  59. Xint    owner[MGKNUM];        /*owner*/
  60. Xint    side[MGKNUM];        /*see definitions->1=units 2=unit*/
  61. Xint    troops[MGKNUM];        /*starting troops in army */
  62. Xint    anation;        /*nation attacking in this fight*/
  63. Xint    dnation;        /*one nation defending in this fight*/
  64. X
  65. X/*RESOLVE COMBAT RESULTS */
  66. X/*attacker wants a high roll and defender wants low roll on both dice*/
  67. X/*       0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9*/
  68. X
  69. Xint Cbt6_1[]={
  70. X20,20,20,20,20,15,10,10,10,10,5,5,5,5,5,0,0,0,0,0,0
  71. X};
  72. Xint Cbt5_1[]={
  73. X40,30,20,20,20,20,20,20,10,10,10,10,5,5,5,0,0,0,0,0,0
  74. X};
  75. Xint Cbt4_1[]={
  76. X50,40,30,30,30,20,20,20,20,10,10,10,10,5,5,5,0,0,0,0,0
  77. X};
  78. Xint Cbt3_1[]={
  79. X60,50,40,30,30,30,20,20,20,20,10,10,10,10,5,5,5,0,0,0,0
  80. X};
  81. Xint Cbt2_1[]={
  82. X70,50,40,40,40,40,30,30,20,20,20,20,10,10,10,10,10,5,5,5,0
  83. X};
  84. Xint Cbt3_2[]={
  85. X80,60,40,40,40,40,30,30,30,30,20,20,20,20,20,20,20,10,10,10,0
  86. X};
  87. Xint Cbt5_4[]={
  88. X90,60,50,50,50,50,40,40,30,30,30,30,30,30,30,30,30,20,10,10,10
  89. X};
  90. Xint Cbt1_1[]={
  91. X100,90,60,60,60,60,50,50,40,40,40,40,30,30,30,30,20,20,20,10,10
  92. X};
  93. Xint Cbt4_5[]={
  94. X100,90,80,70,70,70,60,60,50,50,50,50,40,40,40,40,40,30,20,20,10
  95. X};
  96. Xint Cbt2_3[]={
  97. X110,90,80,80,70,70,60,60,50,50,50,50,40,40,40,40,40,40,30,20,10
  98. X};
  99. Xint Cbt1_2[]={
  100. X110,100,100,90,80,80,80,80,70,60,60,60,50,50,50,50,50,40,30,30,10
  101. X};
  102. Xint Cbt1_3[]={
  103. X120,110,110,100,90,90,90,90,80,80,70,70,70,70,60,50,50,40,30,30,20
  104. X};
  105. Xint Cbt1_4[]={
  106. X120,110,100,100,90,90,90,90,80,80,70,70,70,70,60,50,50,40,30,30,20
  107. X};
  108. Xint Cbt1_5[]={
  109. X130,110,110,100,100,90,90,90,80,80,70,70,70,70,60,50,50,40,40,30,20
  110. X};
  111. Xint Cbt1_6[]={
  112. X130,120,110,110,110,100,100,90,90,90,80,80,80,70,70,50,50,40,40,40,40
  113. X};
  114. X
  115. X
  116. X/*run all combat on map
  117. X *  procedure is to find each sector with armies in attack mode and
  118. X *  then search around them
  119. X */
  120. Xvoid
  121. Xcombat()
  122. X{
  123. X    register int i,j;
  124. X    /*if fought is 1 then do not fight a second battle in sector*/
  125. X    short fought[MAPX][MAPY];
  126. X    int temp;
  127. X    short armynum,nvynum;
  128. X    int valid;
  129. X    int count=0;
  130. X
  131. X    printf("RUN COMBAT SUBROUTINES");
  132. X    fprintf(fnews,"4\tBATTLE SUMMARY STATISTICS\n");
  133. X    /*for each nation, if in attack mode run a check*/
  134. X
  135. X    for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++) fought[i][j]=0;
  136. X
  137. X    for(anation=0;anation<NTOTAL;anation++) if(ntn[anation].active>0) {
  138. X
  139. X        /*army combat*/
  140. X        for(j=0;j<MAXARM;j++) if((ntn[anation].arm[j].stat==ATTACK)
  141. X            &&(ntn[anation].arm[j].sold>0)
  142. X            &&(fought[ntn[anation].arm[j].xloc][ntn[anation].arm[j].yloc]==0)){
  143. X
  144. X            fought[ntn[anation].arm[j].xloc][ntn[anation].arm[j].yloc]=1;
  145. X            /*initialize matrix*/
  146. X            for(temp=0;temp<MGKNUM;temp++){
  147. X                unit[temp]=(-1);
  148. X                owner[temp]=(-1);
  149. X                side[temp]=(-1);
  150. X                troops[temp]=0;
  151. X            }
  152. X
  153. X            /*check all armies in area and add to matrix*/
  154. X            count=0;
  155. X            valid=FALSE;
  156. X            /*is valid,set matrix*/
  157. X            for(country=0;country<NTOTAL;country++)
  158. X            if(ntn[country].active!=0)
  159. X            for(armynum=0;armynum<MAXARM;armynum++)
  160. X            if((ASOLD>0)
  161. X            &&(ASTAT!=SCOUT)
  162. X            &&(AXLOC==ntn[anation].arm[j].xloc)
  163. X            &&(AYLOC==ntn[anation].arm[j].yloc)
  164. X            &&(count<MGKNUM)) {
  165. X
  166. X                if((country!=anation)
  167. X                &&(ntn[anation].dstatus[country]>HOSTILE)) {
  168. X                    valid=TRUE;
  169. X                    dnation=country;
  170. X                }
  171. X                unit[count]=armynum;
  172. X                owner[count]=country;
  173. X                count++;
  174. X            }
  175. X
  176. X            if(valid==TRUE) fight();
  177. X        }
  178. X
  179. X        /*navy combat*/
  180. X        for(j=0;j<MAXNAVY;j++)
  181. X        if((ntn[anation].nvy[j].warships>0)
  182. X&&(fought[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc]==0)
  183. X&&(sct[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc].altitude==WATER)){
  184. X
  185. X         fought[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc]=1;
  186. X
  187. X            /*initialize matrix*/
  188. X            for(temp=0;temp<MGKNUM;temp++){
  189. X                unit[temp]=(-1);
  190. X                owner[temp]=(-1);
  191. X                side[temp]=(-1);
  192. X                troops[temp]=0;
  193. X            }
  194. X
  195. X            /*check all fleets in 1 sector range and add to matrix*/
  196. X            count=0;
  197. X            valid=FALSE;
  198. X            /*is valid,set matrix*/
  199. X            for(country=0;country<NTOTAL;country++)
  200. X            if(ntn[country].active!=0)
  201. X            for(nvynum=0;nvynum<MAXNAVY;nvynum++)
  202. X            if((NWAR+NMER>0)
  203. X            &&(abs(NXLOC-ntn[anation].nvy[j].xloc)<=1)
  204. X            &&(abs(NYLOC-ntn[anation].nvy[j].yloc)<=1)
  205. X            &&(count<MGKNUM)) {
  206. X                fought[NXLOC][NYLOC]=1;
  207. X                if((country!=anation)
  208. X                &&(ntn[anation].dstatus[country]>HOSTILE)){
  209. X                    valid=TRUE;
  210. X                    dnation=country;
  211. X                }
  212. X                unit[count]=nvynum;
  213. X                owner[count]=country;
  214. X                count++;
  215. X            }
  216. X            if(valid==TRUE) navalcbt();
  217. X        }
  218. X    }
  219. X    printf("\nall army and navy attacks completed");
  220. X}
  221. X
  222. X/*taking the three matrices, run a combat*/
  223. Xvoid
  224. Xfight()
  225. X{
  226. X    FILE *fpmsg, *fopen();
  227. X    char tempstr[15];
  228. X    int droll,aroll;
  229. X    int odds;        /*odds total times 100*/
  230. X    int done;
  231. X    int i,j,k;
  232. X    int asold=0,dsold=0;    /*a's and d's total soldiers*/
  233. X    int Aloss=0,Dloss=0;    /*a's and d's total losses*/
  234. X    int PAloss,PDloss;    /*percent a and d loss*/
  235. X    int loss,divisor;
  236. X    int abonus=0,dbonus=0;        /*bonus aggregate*/
  237. X    short vampire=0;        /*# non vamps deaded */
  238. X    short nvamps=0;            /*number of vampire armies*/
  239. X
  240. X    /* determine who is attacker & who is on defenders side?*/
  241. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  242. X        if(owner[j]==anation) side[j]=ATKR;
  243. X        else if(owner[j]==dnation) side[j]=DFND;
  244. X        else if(ntn[anation].dstatus[owner[j]]==JIHAD) side[j]=DFND;
  245. X        else if(ntn[owner[j]].dstatus[anation]==JIHAD) side[j]=DFND;
  246. X        else if(ntn[anation].dstatus[owner[j]]==WAR)   side[j]=DFND;
  247. X        else if(ntn[owner[j]].dstatus[anation]==WAR)   side[j]=DFND;
  248. X        else if((ntn[owner[j]].dstatus[anation]==CONFEDERACY)&&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR;
  249. X        else if((ntn[owner[j]].dstatus[anation]==ALLIED)&&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR;
  250. X    }
  251. X
  252. X    /*calculate number of troops */
  253. X    asold=0;
  254. X    dsold=0;
  255. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) {
  256. X        if(side[i]==ATKR){
  257. X            troops[i] = ntn[owner[i]].arm[unit[i]].sold;
  258. X            asold += ntn[owner[i]].arm[unit[i]].sold;
  259. X        } else if(side[i]==DFND){
  260. X            troops[i] = ntn[owner[i]].arm[unit[i]].sold;
  261. X            dsold += ntn[owner[i]].arm[unit[i]].sold;
  262. X        }
  263. X        if(magic(owner[i],VAMPIRE)==1) nvamps++;
  264. X    }
  265. X
  266. X    if((dsold<=0)||(asold<=0)) {
  267. X        printf("\nERROR CONDITION -- ABORTING THIS COMBAT!!!!!!\n");
  268. X        return;
  269. X    }
  270. X    odds = (asold*100)/dsold;
  271. X
  272. X    /* CALCULATE WEIGHTED AVERAGE BONUS*/
  273. X    abonus=0;
  274. X    dbonus=0;
  275. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) {
  276. X        if(side[i]==ATKR)
  277. X            abonus += cbonus(i)*troops[i];
  278. X        else if(side[i]==DFND)
  279. X            dbonus += cbonus(i)*troops[i];
  280. X    }
  281. X
  282. X    /*archer bonus if not in fort vs kinghts/cavalry*/
  283. X    j=0;
  284. X    k=0;
  285. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1))
  286. X
  287. X    if(sct[ntn[owner[i]].arm[unit[i]].xloc][ntn[owner[i]].arm[unit[i]].yloc].fortress==0){
  288. X        if((ntn[owner[i]].arm[unit[i]].unittyp == A_CAVALRY)
  289. X        ||(ntn[owner[i]].arm[unit[i]].unittyp == A_KNIGHT))
  290. X        if(side[i]==ATKR) j+=troops[i];
  291. X        else if(side[i]==DFND) k+=troops[i];
  292. X    }
  293. X
  294. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) {
  295. X    if(j>0) abonus += (15 * j * troops[i]) / asold;
  296. X    if(k>0) dbonus += (15 * k * troops[i]) / dsold;
  297. X    }
  298. X
  299. X    abonus/=asold;
  300. X    dbonus/=dsold;
  301. X
  302. X/*CALCULATED BONUSES TO WHOLE COMBAT*/
  303. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) {
  304. X        if(sct[ntn[owner[i]].arm[unit[i]].xloc][ntn[owner[i]].arm[unit[i]].yloc].fortress != 0){
  305. X        /*Catapults add +1%/20 men defending castle (max +10%)*/
  306. X        if((ntn[owner[i]].arm[unit[i]].unittyp == A_CATAPULT)
  307. X            &&(side[i]==DFND))
  308. X            abonus += max((troops[i]/20),10);
  309. X        /*Seige_engines add +1%/20 men when attacking fortress*/
  310. X        else if((ntn[owner[i]].arm[unit[i]].unittyp == A_SEIGE)
  311. X            &&(side[i]==ATKR))
  312. X            abonus += max((troops[i]/20),30);
  313. X        }
  314. X        else {
  315. X        /*Catapults add +1%/40 men normal combat (max +10%)*/
  316. X        if(ntn[owner[i]].arm[unit[i]].unittyp == A_CATAPULT)
  317. X            abonus+=max((troops[i]/40),10);
  318. X        }
  319. X    }
  320. X
  321. X    /*RUN COMBAT */
  322. X    /*DICE RESULTS MAY BE FROM 0 TO 200*/
  323. X    /*attacker wants a high roll and defender wants low roll on both dice*/
  324. X    aroll =   abs(rand()%100);
  325. X    aroll +=  50 + abonus - dbonus;
  326. X    if(aroll<0) aroll=0;
  327. X    if(aroll>199) aroll=199;
  328. X
  329. X    droll =   abs(rand()%100);
  330. X    droll +=  50 + abonus - dbonus;
  331. X    if(droll<0) droll=0;
  332. X    if(droll>199) droll=199;
  333. X
  334. X    /*odds bonus*/
  335. X    if(odds>1500) {
  336. X        PAloss = (Cbt6_1[aroll/10])/4;
  337. X        PDloss = Cbt1_6[20-droll/10]+30;
  338. X    } else if(odds>600) {
  339. X        PAloss = Cbt6_1[aroll/10];
  340. X        PDloss = Cbt1_6[20-droll/10];
  341. X    } else if(odds>500){
  342. X        PAloss = Cbt5_1[aroll/10];
  343. X        PDloss = Cbt1_5[20-droll/10];
  344. X    } else if(odds>400){
  345. X        PAloss = Cbt4_1[aroll/10];
  346. X        PDloss = Cbt1_4[20-droll/10];
  347. X    } else if(odds>300) {
  348. X        PAloss = Cbt3_1[aroll/10];
  349. X        PDloss = Cbt1_3[20-droll/10];
  350. X    } else if(odds>200) {
  351. X        PAloss = Cbt2_1[aroll/10];
  352. X        PDloss = Cbt1_2[20-droll/10];
  353. X    } else if(odds>150) {
  354. X        PAloss = Cbt3_2[aroll/10];
  355. X        PDloss = Cbt2_3[20-droll/10];
  356. X    } else if(odds>125) {
  357. X        PAloss = Cbt5_4[aroll/10];
  358. X        PDloss = Cbt4_5[20-droll/10];
  359. X    } else if(odds>100){
  360. X        PAloss = Cbt1_1[aroll/10];
  361. X        PDloss = Cbt1_1[20-droll/10];
  362. X    } else if(odds>75) {
  363. X        PAloss = Cbt4_5[aroll/10];
  364. X        PDloss = Cbt5_4[20-droll/10];
  365. X    } else if(odds>50) {
  366. X        PAloss = Cbt1_2[aroll/10];
  367. X        PDloss = Cbt2_1[20-droll/10];
  368. X    } else if(odds>33) {
  369. X        PAloss = Cbt1_3[aroll/10];
  370. X        PDloss = Cbt3_1[20-droll/10];
  371. X    } else if(odds>15) {
  372. X        PAloss = Cbt1_6[aroll/10];
  373. X        PDloss = Cbt6_1[20-droll/10];
  374. X    } else {
  375. X        PAloss = 120;
  376. X        PDloss = 0;
  377. X    }
  378. X
  379. X    retreatside = 0;
  380. X
  381. X    if((PDloss > 2* PAloss)
  382. X    &&(PDloss>=50)
  383. X    &&(odds>150)
  384. X    &&(rand()%4==0))    retreatside=DFND;
  385. X
  386. X    if((PAloss > 2* PDloss)
  387. X    &&(PAloss>=50)
  388. X    &&(odds<150)
  389. X    &&(rand()%2==0))    retreatside=ATKR;
  390. X
  391. X    if(retreatside!=0) {
  392. X        fdxyretreat();
  393. X        /* no legal retreat route */
  394. X        if((retreatx== ntn[owner[0]].arm[unit[0]].xloc)
  395. X        && (retreaty== ntn[owner[0]].arm[unit[0]].yloc)){
  396. X            if(retreatside==ATKR) PAloss+=10;
  397. X            else PDloss+=10;
  398. X#ifdef DEBUG
  399. X    printf("side %d (%d %d) cant retreat...+10% loss\n",retreatside,retreatx,retreaty);
  400. X#endif DEBUG
  401. X        }
  402. X#ifdef DEBUG
  403. X    else
  404. X    printf("retreat side %d to %d %d\n",retreatside,retreatx,retreaty);
  405. X#endif DEBUG
  406. X    }
  407. X
  408. X    /*divisor is the smallest combat bonus*/
  409. X    divisor = 100;
  410. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){
  411. X        if(side[i]==ATKR)
  412. X        divisor= min (divisor,ntn[owner[i]].aplus);
  413. X        else
  414. X        divisor= min (divisor,ntn[owner[i]].dplus);
  415. X    }
  416. X    divisor+=100;
  417. X
  418. X    /*NOTE LOSSES ARE ADJUSTED BY CBONUS*/
  419. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){
  420. X        if(side[i]==ATKR){
  421. X            if( ntn[owner[i]].arm[unit[i]].unittyp >= MINMONSTER) {
  422. X                if((rand()%100) < PAloss){ /* kill it */
  423. X                    Aloss += troops[i];
  424. X                    ntn[owner[i]].arm[unit[i]].sold=0;
  425. X                }
  426. X            } else {
  427. X            loss=(troops[i]*PAloss*divisor) /(100*(100+ntn[owner[i]].aplus));
  428. X            if(loss>troops[i] )
  429. X                loss=troops[i];
  430. X            /*army can't have less than 25 men in it*/
  431. X            if(troops[i]-loss<25)
  432. X                loss=troops[i];
  433. X            Aloss+=loss;
  434. X            ntn[owner[i]].arm[unit[i]].sold-=loss;
  435. X            }
  436. X        } else if(side[i]==DFND){
  437. X            if( ntn[owner[i]].arm[unit[i]].unittyp >= MINMONSTER) {
  438. X                if((rand()%100) < PDloss){ /* kill it */
  439. X                    Dloss +=troops[i];
  440. X                    ntn[owner[i]].arm[unit[i]].sold=0;
  441. X                }
  442. X            } else {
  443. X            loss=(troops[i]*PDloss*divisor)/(100*(100+ntn[owner[i]].dplus));
  444. X            if(loss>troops[i] )
  445. X                loss=troops[i];
  446. X            /*destroy army if < 25 men*/
  447. X            if(troops[i]-loss<25)
  448. X                loss=troops[i];
  449. X            Dloss+=loss;
  450. X            ntn[owner[i]].arm[unit[i]].sold-=loss;
  451. X            }
  452. X        }
  453. X        if((nvamps>0)&&(magic(owner[i],VAMPIRE)==1))
  454. X            vampire+= loss / 3;
  455. X    }
  456. X#ifdef HIDELOC
  457. X    fprintf(fnews,"4.\tBattle occurs in %s", ntn[sct[ntn[owner[0]].arm[unit[0]].xloc][ntn[owner[0]].arm[unit[0]].yloc].owner].name);
  458. X#else
  459. X    fprintf(fnews,"4.\tBattle in %d,%d",ntn[owner[0]].arm[unit[0]].xloc, ntn[owner[0]].arm[unit[0]].yloc);
  460. X#endif
  461. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  462. X        done=FALSE;
  463. X        for(i=0;i<j;i++) if(owner[j]==owner[i]) done=TRUE;
  464. X        if(done==FALSE) {
  465. X        if(side[i]==ATKR)
  466. X        fprintf(fnews,", attacker %s",ntn[owner[j]].name);
  467. X        else if(side[i]==DFND)
  468. X        fprintf(fnews,", defender %s",ntn[owner[j]].name);
  469. X        }
  470. X    }
  471. X    fprintf(fnews,"\n");
  472. X    if(nvamps>0){
  473. X        for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){
  474. X            if(magic(owner[i],VAMPIRE)==1)
  475. X            ntn[owner[i]].arm[unit[i]].sold+=vampire/nvamps;
  476. X        }
  477. X    }
  478. X
  479. X    /*who is in the battle*/
  480. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  481. X        done=FALSE;
  482. X
  483. X        /*first time your nation appears done=FALSE*/
  484. X        for(i=0;i<j;i++) if(owner[j]==owner[i]) done=TRUE;
  485. X
  486. X        if((done==FALSE)&&(ntn[owner[j]].active==1)) {
  487. X            sprintf(tempstr,"%s%d",msgfile,owner[j]);
  488. X            if ((fpmsg=fopen(tempstr,"a+"))==NULL) {
  489. X                printf("\n\tERROR OPENING %s",tempstr);
  490. X                exit(FAIL);
  491. X            }
  492. X
  493. X            fprintf(fpmsg,"%s\tBATTLE SUMMARY for sector %d, %d\n",ntn[owner[j]].name,ntn[owner[0]].arm[unit[0]].xloc, ntn[owner[0]].arm[unit[0]].yloc);
  494. X
  495. X            if(side[j]==ATKR) fprintf(fpmsg,"%s\tYou are on the Attacking Side\n",ntn[owner[j]].name);
  496. X            else fprintf(fpmsg,"%s\tYou are on the Defending Side\n",ntn[owner[j]].name);
  497. X
  498. X            /*detail all participants in battle*/
  499. X            for(k=0;k<MGKNUM;k++) if(owner[k]!=(-1)){
  500. X                if(side[k]==DFND)
  501. X                fprintf(fpmsg,"%s\t%s is defending with army %d (type %s, men %d, bonus=%d)\n",
  502. X                ntn[owner[j]].name,
  503. X                ntn[owner[k]].name,
  504. X                unit[k],
  505. X                unittype[ntn[owner[k]].arm[unit[k]].unittyp%100],
  506. X                troops[k],
  507. X                cbonus(k));
  508. X                else if(side[k]==ATKR)
  509. X                fprintf(fpmsg,"%s\t%s is attacking with army %d (type %s, men %d, bonus=%d)\n",
  510. X                ntn[owner[j]].name,
  511. X                ntn[owner[k]].name,
  512. X                unit[k],
  513. X                unittype[ntn[owner[k]].arm[unit[k]].unittyp%100],
  514. X                troops[k],
  515. X                cbonus(k));
  516. X                else
  517. X                fprintf(fpmsg,"%s\t%s is neutral with army %d (type %s, men %d, bonus=%d)\n",
  518. X                ntn[owner[j]].name,
  519. X                ntn[owner[k]].name,
  520. X                unit[k],
  521. X                unittype[ntn[owner[k]].arm[unit[k]].unittyp%100],
  522. X                ntn[owner[k]].arm[unit[k]].sold,
  523. X                cbonus(k));
  524. X            }
  525. X
  526. X            fprintf(fpmsg,"%s\tattacking soldiers=%d\tmodified roll=%d-> attackers percent loss %d%%\n",ntn[owner[j]].name,asold,aroll,PAloss);
  527. X            fprintf(fpmsg,"%s\tdefending soldiers=%d\tmodified roll=%d-> defenders percent loss %d%%\n",ntn[owner[j]].name,dsold,droll,PDloss);
  528. X            fprintf(fpmsg,"%s\tODDS are %d to 100\n",ntn[owner[j]].name,odds);
  529. X            fprintf(fpmsg,"%s\tRESULT: Attackers lose %d men, Defenders lose %d men\n",ntn[owner[j]].name,Aloss, Dloss);
  530. X            if(retreatside==ATKR){
  531. X            fprintf(fpmsg,"%s\t\tAdditionally, All attackers retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty);
  532. X#ifdef DEBUG
  533. X            printf("%s\t\tAdditionally, All attackers retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty);
  534. X#endif DEBUG
  535. X            } else if(retreatside==DFND){
  536. X            fprintf(fpmsg,"%s\t\tAdditionally, All defenders retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty);
  537. X#ifdef DEBUG
  538. X            printf("%s\t\tAdditionally, All defenders retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty);
  539. X#endif DEBUG
  540. X            }
  541. X            fprintf(fpmsg,"%s\n","END");
  542. X            fclose(fpmsg);
  543. X        }
  544. X    }
  545. X    retreat();
  546. X}
  547. X
  548. X/*Subroutine to determine combat bonuses for unit i in matrix*/
  549. X/*    returns int - bonus */
  550. Xint
  551. Xcbonus(num)
  552. X{
  553. X    short armynum;
  554. X    int armbonus;
  555. X
  556. X    armbonus=0;
  557. X    armynum=unit[num];
  558. X    country=owner[num];
  559. X
  560. X    /*Racial combat bonus due to terrain (the faster you move the better)*/
  561. X    armbonus+=5*(9-movecost[AXLOC][AYLOC]);
  562. X
  563. X    if((magic(country,MI_MONST)==1)&&(unit[num]==0)) armbonus+=20;
  564. X    if((magic(country,AV_MONST)==1)&&(unit[num]==0)) armbonus+=20;
  565. X    if((magic(country,MA_MONST)==1)&&(unit[num]==0)) armbonus+=20;
  566. X
  567. X    if(((magic(country,DESTROYER)==1)
  568. X    ||(magic(country,DERVISH)==1))
  569. X    &&((sct[AXLOC][AYLOC].vegetation==ICE)
  570. X    ||(sct[AXLOC][AYLOC].vegetation==DESERT)))
  571. X        armbonus+=30;
  572. X
  573. X    if(side[num]==DFND){
  574. X
  575. X        if(sct[AXLOC][AYLOC].altitude==MOUNTAIN) armbonus+=20;
  576. X        else if(sct[AXLOC][AYLOC].altitude==HILL) armbonus+=10;
  577. X
  578. X        if(sct[AXLOC][AYLOC].vegetation==JUNGLE) armbonus+=20;
  579. X        else if(sct[AXLOC][AYLOC].vegetation==FOREST) armbonus+=15;
  580. X        else if(sct[AXLOC][AYLOC].vegetation==WOOD) armbonus+=10;
  581. X
  582. X        armbonus += ntn[owner[num]].dplus;
  583. X
  584. X        if(sct[AXLOC][AYLOC].designation==DCASTLE)
  585. X            armbonus+=5*sct[AXLOC][AYLOC].fortress;
  586. X        else if((ASTAT==GARRISON)
  587. X        &&(sct[AXLOC][AYLOC].designation==DCITY)){
  588. X            if(magic(country,ARCHITECT)==1){
  589. X                armbonus+=10+16*sct[AXLOC][AYLOC].fortress;
  590. X            }
  591. X            else armbonus+=10+8*sct[AXLOC][AYLOC].fortress;
  592. X        }
  593. X        else if((ASTAT==GARRISON)
  594. X        &&(sct[AXLOC][AYLOC].designation==DCAPITOL)){
  595. X            if(magic(country,ARCHITECT)==1){
  596. X                armbonus+=20+20*sct[AXLOC][AYLOC].fortress;
  597. X            }
  598. X            else armbonus+=20+10*sct[AXLOC][AYLOC].fortress;
  599. X        }
  600. X
  601. X    }
  602. X    else if(side[num]==ATKR) armbonus += ntn[owner[num]].aplus;
  603. X
  604. X    /*army status is important*/
  605. X    if(ASTAT==MARCH) armbonus-=40;
  606. X
  607. X    /*if a fortress*/
  608. X    if(sct[AXLOC][AYLOC].fortress!=0){
  609. X        /*Cavalry and Knights get -20%*/
  610. X        if((ATYPE == A_CAVALRY) ||(ATYPE == A_KNIGHT)) armbonus -= 20;
  611. X        /*Archers gain pluses*/
  612. X        else if((ATYPE == A_ARCHER)&&(side[num]==DFND)) armbonus += 15;
  613. X        else if((ATYPE == A_ARCHER)&&(side[num]==ATKR)) armbonus += 5;
  614. X    }
  615. X
  616. X    /*Phalanx and Legionaires need certain numbers of troops*/
  617. X    if(((ATYPE!=A_PHALANX) || (ASOLD>500))
  618. X    &&((ATYPE!=A_LEGION) || (ASOLD>1000))){
  619. X        if(side[num]==ATKR) armbonus+= *(unitattack+(ATYPE%100));
  620. X        else armbonus+= *(unitdefend+(ATYPE%100));
  621. X    }
  622. X
  623. X    return(armbonus);
  624. X}
  625. X
  626. Xfdxyretreat()    /* finds retreat location */
  627. X{
  628. X    int x,y,nation=(-1);
  629. X    int xsctr= ntn[owner[0]].arm[unit[0]].xloc;
  630. X    int ysctr= ntn[owner[0]].arm[unit[0]].yloc;
  631. X
  632. X    if((sct[xsctr][ysctr].designation==DCITY)
  633. X    ||(sct[xsctr][ysctr].designation==DCAPITOL)){
  634. X        retreatside=0;
  635. X        return;
  636. X    }
  637. X    retreatx=xsctr;
  638. X    retreaty=ysctr;
  639. X
  640. X    if(retreatside == ATKR) nation=anation;
  641. X    else nation=dnation;
  642. X
  643. X    for(x= xsctr-1; x<=xsctr+1; x++)
  644. X    for(y= ysctr-1; y<=ysctr+1; y++) if(ONMAP){
  645. X        if(tofood(sct[x][y].vegetation,0)==0) continue;
  646. X        if(((sct[x][y].owner == nation)
  647. X           ||(ntn[sct[x][y].owner].dstatus[nation] < NEUTRAL))
  648. X        ||(solds_in_sector( x, y, sct[x][y].owner) == 0)){
  649. X            retreatx=x;
  650. X            retreaty=y;
  651. X#ifdef DEBUG
  652. X            printf("%d %d RETREAT TO %d %d\n",xsctr,ysctr,x,y);
  653. X#endif DEBUG
  654. X            return;
  655. X        }
  656. X    }
  657. X}
  658. X
  659. Xretreat()
  660. X{
  661. X    int cnum;
  662. X
  663. X    if(retreatside == 0) return;
  664. X
  665. X    for(cnum=0;cnum<MGKNUM;cnum++) if(owner[cnum]!=(-1)){
  666. X        if(owner[cnum] > MAXNTN ) continue;    /*monsts dont retreat */
  667. X        if((side[cnum]==ATKR)&&(retreatside==ATKR)){
  668. X            ntn[owner[cnum]].arm[unit[cnum]].xloc = retreatx;
  669. X            ntn[owner[cnum]].arm[unit[cnum]].yloc = retreaty;
  670. X        }
  671. X        else if((side[cnum]==DFND)&&(retreatside==DFND)){
  672. X            ntn[owner[cnum]].arm[unit[cnum]].xloc = retreatx;
  673. X            ntn[owner[cnum]].arm[unit[cnum]].yloc = retreaty;
  674. X        }
  675. X    }
  676. X}
  677. X
  678. X/*SUBROUTINE TO RUN NAVAL COMBAT ON ALL SHIPS */
  679. X/*just like fight, this takes array of owner,side,unit and calculate*/
  680. Xvoid
  681. Xnavalcbt()
  682. X{
  683. X    FILE *fpmsg, *fopen();
  684. X    int sailor;
  685. X    char tempmsg[15];
  686. X    int aship=0,dship=0;    /*a's and d's total war ships*/
  687. X    int asunk=0,dsunk=0;    /*a's and d's losses for the round*/
  688. X    int amsunk=0,dmsunk=0;  /*a's and d's msunks for the round*/
  689. X    register int done,i,j,k;
  690. X
  691. X    /* determine who is attacker & who is on defenders side?*/
  692. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  693. X        if(owner[j]==anation) side[j]=ATKR;
  694. X        else if(ntn[anation].dstatus[owner[j]]==JIHAD) side[j]=DFND;
  695. X        else if(ntn[owner[j]].dstatus[anation]==JIHAD) side[j]=DFND;
  696. X        else if(ntn[anation].dstatus[owner[j]]==WAR)   side[j]=DFND;
  697. X        else if(ntn[owner[j]].dstatus[anation]==WAR)   side[j]=DFND;
  698. X        else if((ntn[owner[j]].dstatus[anation]==CONFEDERACY)
  699. X        &&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR;
  700. X        else if((ntn[owner[j]].dstatus[anation]==ALLIED)
  701. X        &&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR;
  702. X    }
  703. X
  704. X    /*RUN COMBAT; loop until done*/
  705. X    /*determine relative strengths--does anybody try to flee*/
  706. X    /*calculate number of ships on a side*/
  707. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  708. X        if(side[j]==DFND) {
  709. X            dship+=ntn[owner[j]].nvy[unit[j]].warships;
  710. X        }
  711. X        else if(side[j]==ATKR) {
  712. X            aship+=ntn[owner[j]].nvy[unit[j]].warships;
  713. X        }
  714. X    }
  715. X
  716. X    /*no bonus currently included in this combat*/
  717. X
  718. X    /*each warship can do damage 40%; once all warships sunk then all*/
  719. X    /*sunk are captured merchant*/
  720. X    sailor=FALSE;
  721. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)) if(side[j]==ATKR)
  722. X        if(magic(owner[j],SAILOR)==TRUE) sailor=TRUE;
  723. X    if(sailor==TRUE) for(i=0;i<aship;i++) if(rand()%10<=5) dsunk++;
  724. X    else for(i=0;i<aship;i++) if(rand()%10<=3) dsunk++;
  725. X
  726. X    sailor=FALSE;
  727. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)) if(side[j]==DFND)
  728. X        if(magic(owner[j],SAILOR)==TRUE) sailor=TRUE;
  729. X    if(sailor==TRUE) for(i=0;i<dship;i++) if(rand()%10<=4) asunk++;
  730. X    else for(i=0;i<dship;i++) if(rand()%10<=3) asunk++;
  731. X
  732. X#ifdef HIDELOC
  733. X    fprintf(fnews,"4.\tNaval Battle occurs");
  734. X#else
  735. X    fprintf(fnews,"4.\t%d,%d: Naval Battle",ntn[owner[0]].nvy[unit[0]].xloc, ntn[owner[0]].nvy[unit[0]].yloc);
  736. X#endif
  737. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  738. X        k=0;
  739. X        for(i=0;i<j;i++) if(owner[j]==owner[i]) k=1;
  740. X        if(k==0) {
  741. X        if(side[i]==DFND)
  742. X            fprintf(fnews,", attacker %s",ntn[owner[j]].name);
  743. X        else if(side[i]==ATKR)
  744. X            fprintf(fnews,", defender %s",ntn[owner[j]].name);
  745. X        }
  746. X    }
  747. X    fprintf(fnews,"\n");
  748. X
  749. X
  750. X#ifdef HIDELOC
  751. X    fprintf(fnews,"4.\t\tNaval attackers lose %d of %d warships\n",
  752. X        min(asunk,aship),aship);
  753. X    fprintf(fnews,"4.\t\tNaval defenders lose %d of %d warships\n",
  754. X        min(dsunk,dship),dship);
  755. X    fprintf(fnews,"4.\t\tNaval attackers lose %d merchants\n",
  756. X        max(0,asunk-aship));
  757. X    fprintf(fnews,"4.\t\tNaval defenders lose %d merchants\n",
  758. X        max(0,dsunk-dship));
  759. X#else
  760. X    fprintf(fnews,"4.\t%d,%d: Naval attackers lose %d of %d warships\n",
  761. X    ntn[owner[0]].nvy[unit[0]].xloc,
  762. X    ntn[owner[0]].nvy[unit[0]].yloc,min(asunk,aship),aship);
  763. X    fprintf(fnews,"4.\t%d,%d: Naval defenders lose %d of %d warships\n",
  764. X    ntn[owner[0]].nvy[unit[0]].xloc,
  765. X    ntn[owner[0]].nvy[unit[0]].yloc,min(dsunk,dship),dship);
  766. X    fprintf(fnews,"4.\t%d,%d: Naval attackers lose %d merchants\n",
  767. X    ntn[owner[0]].nvy[unit[0]].xloc,
  768. X    ntn[owner[0]].nvy[unit[0]].yloc,max(0,asunk-aship));
  769. X    fprintf(fnews,"4.\t%d,%d: Naval defenders lose %d merchants\n",
  770. X    ntn[owner[0]].nvy[unit[0]].xloc,
  771. X    ntn[owner[0]].nvy[unit[0]].yloc,max(0,dsunk-dship));
  772. X#endif
  773. X
  774. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){
  775. X        if((asunk>0)&&(side[i]==ATKR)){
  776. X            if(asunk > aship ) {
  777. X                ntn[owner[i]].nvy[unit[i]].warships=0;
  778. X                amsunk = asunk - aship;
  779. X            } else  {
  780. X                ntn[owner[i]].nvy[unit[i]].warships -= asunk * ntn[owner[i]].nvy[unit[i]].warships/aship;
  781. X            }
  782. X        }
  783. X        else if((dsunk>0)&&(side[i]==DFND)){
  784. X            if(dsunk > dship ) {
  785. X                ntn[owner[i]].nvy[unit[i]].warships=0;
  786. X                dmsunk = dsunk -dship;
  787. X            } else  {
  788. X                ntn[owner[i]].nvy[unit[i]].warships -= dsunk * ntn[owner[i]].nvy[unit[i]].warships / dship;
  789. X            }
  790. X        }
  791. X    }
  792. X    /* take care of merchants*/
  793. X    for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){
  794. X        if((amsunk>0)&&(side[i]==ATKR)){
  795. X            if(amsunk >= ntn[owner[i]].nvy[unit[i]].merchant ) {
  796. X                amsunk -= ntn[owner[i]].nvy[unit[i]].merchant;
  797. X                ntn[owner[i]].nvy[unit[i]].merchant=0;
  798. X            } else  {
  799. X                ntn[owner[i]].nvy[unit[i]].merchant-=amsunk;
  800. X                amsunk=0;
  801. X            }
  802. X        }
  803. X        else if((dmsunk>0)&&(side[i]==DFND)){
  804. X            if(dmsunk >= ntn[owner[i]].nvy[unit[i]].merchant ) {
  805. X                dmsunk -= ntn[owner[i]].nvy[unit[i]].merchant;
  806. X                ntn[owner[i]].nvy[unit[i]].merchant=0;
  807. X            } else  {
  808. X                ntn[owner[i]].nvy[unit[i]].merchant-=dmsunk;
  809. X                dmsunk=0;
  810. X            }
  811. X        }
  812. X    }
  813. X
  814. X    /*will round continue; does one side wish to withdraw*/
  815. X
  816. X    /*mail results; who is in the battle*/
  817. X    for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){
  818. X        done=FALSE;
  819. X
  820. X        /*first time your nation appears done=FALSE*/
  821. X        for(i=0;i<j;i++) if(owner[j]==owner[i]) done=TRUE;
  822. X
  823. X        if((done==FALSE)&&(ntn[owner[j]].active==1)) {
  824. X            sprintf(tempmsg,"%s%d",msgfile,owner[j]);
  825. X            if ((fpmsg=fopen(tempmsg,"a+"))==NULL) {
  826. X                fprintf(fnews,"4.\tERROR OPENING %s\n",tempmsg);
  827. X                exit(FAIL);
  828. X            }
  829. X
  830. X            fprintf(fpmsg,"%s NAVAL BATTLE in sector %d %d\n"
  831. X            ,ntn[owner[j]].name,ntn[owner[0]].nvy[unit[0]].xloc
  832. X            ,ntn[owner[0]].nvy[unit[0]].yloc);
  833. X
  834. X            if(side[j]==ATKR)
  835. X            fprintf(fpmsg,"%s You are on the Attacking Side\n"
  836. X                ,ntn[owner[j]].name);
  837. X            else fprintf(fpmsg,"%s You are on the Defending Side\n"
  838. X                ,ntn[owner[j]].name);
  839. X
  840. X            /*detail all participants in battle*/
  841. X            for(k=0;k<MGKNUM;k++) if(owner[k]!=(-1)){
  842. X                if(side[k]==DFND)
  843. X                fprintf(fpmsg,"%s\t%s is defender with navy %d\n" ,ntn[owner[j]].name , ntn[owner[k]].name,unit[k]);
  844. X                else fprintf(fpmsg,"%s\t%s is attacker with navy %d\n",ntn[owner[j]].name,ntn[owner[k]].name, unit[k]);
  845. X            }
  846. X
  847. X            fprintf(fpmsg,"%s RESULT: Attackers lose %d ships, Defenders lose %d ships\n",ntn[owner[j]].name, asunk,dsunk);
  848. X            fprintf(fpmsg,"%s         Attackers capture %d merchants, Defenders capture %d merchants\n",ntn[owner[j]].name, dmsunk,amsunk);
  849. X            fprintf(fpmsg,"END\n");
  850. X            fclose(fpmsg);
  851. X        }
  852. X    }
  853. X}
  854. END_OF_combat.c
  855. if test 24900 -ne `wc -c <combat.c`; then
  856.     echo shar: \"combat.c\" unpacked with wrong size!
  857. fi
  858. # end of overwriting check
  859. fi
  860. if test -f npc.c -a "${1}" != "-c" ; then 
  861.   echo shar: Will not over-write existing file \"npc.c\"
  862. else
  863. echo shar: Extracting \"npc.c\" \(28401 characters\)
  864. sed "s/^X//" >npc.c <<'END_OF_npc.c'
  865. X/*conquer : Copyright (c) 1988 by Ed Barlow.
  866. X *  I spent a long time writing this code & I hope that you respect this.
  867. X *  I give permission to alter the code, but not to copy or redistribute
  868. X *  it without my explicit permission.  If you alter the code,
  869. X *  please document changes and send me a copy, so all can have it.
  870. X *  This code, to the best of my knowledge works well,  but it is my first
  871. X *  'C' program and should be treated as such.  I disclaim any
  872. X *  responsibility for the codes actions (use at your own risk).  I guess
  873. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  874. X *                                                Ed
  875. X */
  876. X
  877. X#include "header.h"
  878. X#include "data.h"
  879. X#include <ctype.h>
  880. X
  881. Xextern FILE *fnews;
  882. X
  883. Xextern short country;
  884. Xextern int attr[MAPX][MAPY];     /*sector attactiveness*/
  885. Xextern short movecost[MAPX][MAPY];
  886. Xint peace;    /*is 8 if at peace, 12 if at war*/
  887. X
  888. X/*ntn 1 is nation you are updating*/
  889. Xvoid
  890. Xnewdip(ntn1,ntn2)
  891. X{
  892. X    if(ntn[ntn1].active<2) {
  893. X        if(ntn[ntn1].dstatus[ntn2]==UNMET)
  894. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  895. X    }
  896. X    else if(ntn[ntn1].race==ntn[ntn2].race){
  897. X        if(rand()%5<3) ntn[ntn1].dstatus[ntn2]=FRIENDLY;
  898. X        else if(rand()%2==0) ntn[ntn1].dstatus[ntn2]=ALLIED;
  899. X        else ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  900. X    }
  901. X    else switch(ntn[ntn1].race) {
  902. X    case DWARF:
  903. X        switch(ntn[ntn2].race) {
  904. X        case ELF:
  905. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  906. X            break;
  907. X        case HUMAN:
  908. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  909. X            break;
  910. X        case ORC:
  911. X        default:
  912. X            ntn[ntn1].dstatus[ntn2]=WAR;
  913. X            break;
  914. X        }
  915. X        break;
  916. X    case ELF:
  917. X        switch(ntn[ntn2].race) {
  918. X        case DWARF:
  919. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  920. X            break;
  921. X        case HUMAN:
  922. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  923. X            break;
  924. X        case ORC:
  925. X        default:
  926. X            ntn[ntn1].dstatus[ntn2]=WAR;
  927. X            break;
  928. X        }
  929. X        break;
  930. X    case ORC:
  931. X        switch(ntn[ntn2].race) {
  932. X        case HUMAN:
  933. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  934. X            break;
  935. X        case DWARF:
  936. X        case ELF:
  937. X        default:
  938. X            ntn[ntn1].dstatus[ntn2]=WAR;
  939. X            break;
  940. X        }
  941. X        break;
  942. X    case HUMAN:
  943. X        switch(ntn[ntn2].race) {
  944. X        case DWARF:
  945. X        case ELF:
  946. X            ntn[ntn1].dstatus[ntn2]=NEUTRAL;
  947. X            break;
  948. X        case ORC:
  949. X            ntn[ntn1].dstatus[ntn2]=HOSTILE;
  950. X            break;
  951. X        default:
  952. X            ntn[ntn1].dstatus[ntn2]=WAR;
  953. X            break;
  954. X        }
  955. X        break;
  956. X    default:
  957. X        ntn[ntn1].dstatus[ntn2]=WAR;
  958. X        break;
  959. X    }
  960. X}
  961. X
  962. Xvoid
  963. Xmonster()
  964. X{
  965. X    short nvynum,armynum;
  966. X    int x, y;
  967. X
  968. X    /*move nomads randomly until within 2 of city then attack*/
  969. X    country=NNOMAD;
  970. X    for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){
  971. X        ASOLD *= 11;
  972. X        ASOLD /= 10;
  973. X        x=AXLOC+rand()%4-2;
  974. X        y=AYLOC+rand()%4-2;
  975. X        if(ONMAP&&(is_habitable(x,y))
  976. X        &&(land_reachp(AXLOC,AYLOC,x,y,ntn[country].arm[armynum].smove,country))){
  977. X            AXLOC=x;
  978. X            AYLOC=y;
  979. X            /*if owned & unoccupied you take & people flee*/
  980. X            if( (sct[x][y].owner) == 0 || solds_in_sector( x, y, sct[x][y].owner) == 0 ) {
  981. X                if(sct[x][y].owner==0)
  982. X                    fprintf(fnews,"3.\tnomads take sector %d,%d\n",x,y);
  983. X                else fprintf(fnews,"3.\tnomads capture sector %d,%d\n",x,y);
  984. X                if(sct[x][y].owner!=0) flee(x,y,1,FALSE);
  985. X                sct[x][y].owner=NNOMAD;
  986. X                sct[x][y].designation=DDEVASTATED;
  987. X            }
  988. X        }
  989. X    }
  990. X    else {
  991. X        /*place a new Nomad army*/
  992. X        x=(rand()%(MAPX-8))+4;
  993. X        y=(rand()%(MAPY-8))+4;
  994. X        if((rand()%4==0)&&(is_habitable(x,y))) {
  995. X            AXLOC=x;
  996. X            AYLOC=y;
  997. X            ASOLD=100+100*(rand()%10);
  998. X            ATYPE=A_INFANTRY;
  999. X            ASTAT=ATTACK;
  1000. X        }
  1001. X    }
  1002. X    country=NLIZARD;
  1003. X    for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){
  1004. X        ASOLD*=105;
  1005. X        ASOLD/=100;
  1006. X    }
  1007. X    country=NPIRATE;
  1008. X    fprintf(fnews,"2.\t%s are updated\n",ntn[NPIRATE].name);
  1009. X    /*if pirate fleet within 3 attack if outnumber any fleets */
  1010. X    for(nvynum=0;nvynum<MAXNAVY;nvynum++){
  1011. X        for(x=1;x<MAXNTN;x++) for(y=0;y<MAXNAVY;y++)
  1012. X        if((ntn[x].nvy[y].xloc-NXLOC<2)
  1013. X        &&(sct[ntn[x].nvy[y].xloc][ntn[x].nvy[y].yloc].altitude==WATER)
  1014. X        &&(ntn[x].nvy[y].xloc-NXLOC>(-2))
  1015. X        &&(ntn[x].nvy[y].yloc-NYLOC<2)
  1016. X        &&(ntn[x].nvy[y].yloc-NYLOC>(-2))){
  1017. X            NXLOC= ntn[x].nvy[y].xloc;
  1018. X            NYLOC= ntn[x].nvy[y].yloc;
  1019. X        }
  1020. X        /*add one warship to random pirate fleet*/
  1021. X        if((NWAR>0)&&(rand()%3==0)) {
  1022. X            NWAR++;
  1023. X            NCREW+=SHIPCREW;
  1024. X        }
  1025. X    }
  1026. X}
  1027. X
  1028. X#ifdef NPC
  1029. X
  1030. Xvoid
  1031. Xn_redes(x,y,goldthresh,ironthresh,citythresh)
  1032. Xint goldthresh,ironthresh,citythresh;
  1033. X{
  1034. X    register struct s_sector    *sptr = &sct[x][y];
  1035. X
  1036. X    if(sptr->designation == DCAPITOL) return;
  1037. X
  1038. X    /*large enough for a city now?*/
  1039. X    if(((sptr->people > (spread.civilians/CITYLIMIT))
  1040. X    ||((spread.civilians<30000)&&(sptr->people>1000)))
  1041. X    &&( spread.food > spread.civilians*3)
  1042. X    &&( sptr->iron < ironthresh)
  1043. X    &&( spread.incity+spread.incap < spread.civilians * CITYPERCENT / 100)
  1044. X    &&( spread.sectors > 10)
  1045. X    &&( sptr->gold < goldthresh)){
  1046. X        sptr->designation=DCITY;
  1047. X        spread.incity+=sptr->people;
  1048. X        spread.infarm-=sptr->people;
  1049. X    }
  1050. X
  1051. X    /*not large enough for city and not enough food*/
  1052. X    if((sptr->designation==DCITY)
  1053. X    &&( spread.food < spread.civilians*2)
  1054. X    &&( tofood(sptr->vegetation,sptr->owner) > citythresh )){
  1055. X        sptr->designation=DFARM;
  1056. X        spread.incity-=sptr->people;
  1057. X        spread.infarm+=sptr->people;
  1058. X    }
  1059. X
  1060. X    if((sptr->designation==DCITY)
  1061. X    &&( spread.incity+spread.incap > spread.civilians * CITYPERCENT / 66)){
  1062. X        sptr->designation=DFARM;
  1063. X        spread.incity-=sptr->people;
  1064. X        spread.infarm+=sptr->people;
  1065. X    }
  1066. X
  1067. X    /*what if it is not a city*/
  1068. X    if((sptr->designation!=DCITY)&&(sptr->designation!=DCAPITOL)){
  1069. X        if(( sptr->gold >= goldthresh+2 )
  1070. X        &&( sptr->iron < sptr->gold )){
  1071. X            sptr->designation=DGOLDMINE;
  1072. X        }
  1073. X        else if( sptr->iron >= ironthresh ){
  1074. X            sptr->designation=DMINE;
  1075. X        }
  1076. X        else if( sptr->gold >= goldthresh ){
  1077. X            sptr->designation=DGOLDMINE;
  1078. X        }
  1079. X        else sptr->designation=DFARM;
  1080. X    }
  1081. X}
  1082. X
  1083. Xvoid
  1084. Xredomil()
  1085. X{
  1086. X    short x,y,armynum;
  1087. X    int i, free, done, ideal, militia=0;
  1088. X    long diff=0;
  1089. X    int ok;
  1090. X
  1091. X#ifdef DEBUG
  1092. X    check(__LINE__);
  1093. X#endif DEBUG
  1094. X    /* check out any ship crews */
  1095. X    for(armynum=1;armynum<MAXNAVY;armynum++) {
  1096. X        if((ntn[country].nvy[armynum].merchant>0)
  1097. X        || (ntn[country].nvy[armynum].warships>0))
  1098. X        ntn[country].nvy[armynum].crew =
  1099. X        (ntn[country].nvy[armynum].merchant+ntn[country].nvy[armynum].warships)*SHIPCREW;
  1100. X    }
  1101. X#ifdef DEBUG
  1102. X    check(__LINE__);
  1103. X#endif DEBUG
  1104. X    /* code to check and move armies back if they are too far out */
  1105. X    for(armynum=1;armynum<MAXARM;armynum++) if(ASOLD>0){
  1106. X        ok = 0;
  1107. X        for(x=AXLOC-3;x<=AXLOC+3;x++)
  1108. X            for(y=AYLOC-3;y<=AYLOC+3;y++)
  1109. X                if((ONMAP)&&(sct[x][y].owner==country)) ok=1;
  1110. X        if(ok==0){
  1111. X            AXLOC=ntn[country].capx;
  1112. X            AYLOC=ntn[country].capy;
  1113. X        }
  1114. X    }
  1115. X    for(armynum=1;armynum<MAXARM;armynum++)
  1116. X    if((ASOLD>0)&&(ATYPE==A_MILITIA)){
  1117. X        militia+=ASOLD;
  1118. X    }
  1119. X    ntn[country].tmil -= militia;
  1120. X
  1121. X    /*make sure enough men in army 0 -- garrison duty in capitol*/
  1122. X    armynum=0;
  1123. X    ASTAT=GARRISON;
  1124. X    ATYPE=A_INFANTRY;
  1125. X    AXLOC=ntn[country].capx;
  1126. X    AYLOC=ntn[country].capy;
  1127. X
  1128. X    /*Ideally ASOLD[0]*MILINCAP=tmil*peace/10*/
  1129. X    ideal = ntn[country].tmil * peace / (10*MILINCAP);
  1130. X    if(ntn[country].tgold < 0) ideal/=2;
  1131. X#ifdef DEBUG
  1132. X    if(peace==8)
  1133. X        printf("\t%s IS AT PEACE - garrison in cap is %d, ideal is %d\n",ntn[country].name,ASOLD,ideal);
  1134. X    else if(peace==12)
  1135. X        printf("\t%s IS AT WAR - garrison in cap is %d, ideal is %d\n",ntn[country].name,ASOLD,ideal);
  1136. X    else printf("error - incap is %d ideal is %d\n",ASOLD,ideal);
  1137. X#endif DEBUG
  1138. X
  1139. X    /*MILRATIO ratio mil:civ for non player countries*/
  1140. X    /*MILINCAP ratio (mil in cap):mil for NPCs*/
  1141. X#ifdef DEBUG
  1142. X    check(__LINE__);
  1143. X#endif DEBUG
  1144. X
  1145. X    if((ASOLD*10) < (9*ideal)){
  1146. X
  1147. X    /*too few soldiers on garrison*/
  1148. X    /*diff is number to change mil in cap (>0)*/
  1149. X    if(ntn[country].tgold<0L) diff=0;
  1150. X    else diff = (long) min(ideal-ASOLD,(int) (ntn[country].tiron / *(u_eniron + (ATYPE%100))));
  1151. X
  1152. X    diff = (long) min ((int) diff, sct[ntn[country].capx][ntn[country].capy].people/2);
  1153. X
  1154. X    if(ntn[country].tgold<0 || ntn[country].tiron<0) if(diff > 0) diff=0;
  1155. X
  1156. X#ifdef DEBUG
  1157. X    printf("\tadding %d men to garrison (too few men on garrison)\n",diff);
  1158. X#endif DEBUG
  1159. X
  1160. X    sct[ntn[country].capx][ntn[country].capy].people-=diff;
  1161. X    ASOLD+=diff;
  1162. X    ntn[country].tciv-=diff;
  1163. X    ntn[country].tmil+=diff;
  1164. X    if(magic(country,WARRIOR)==1)    /* take WARRIOR power into account */
  1165. X        ntn[country].tgold -= (diff * *(u_encost + (ATYPE%100))) / 2;
  1166. X    else ntn[country].tgold-=diff* *(u_encost + (ATYPE%100));
  1167. X    ntn[country].tiron-=(diff* *(u_eniron + (ATYPE%100)));
  1168. X#ifdef DEBUG
  1169. X    if(ASOLD < 0) printf("error 2... ASOLD=%d <0\n",ASOLD);
  1170. X#endif DEBUG
  1171. X    }
  1172. X    /*else split garrison army if 1.25* needed number*/
  1173. X    else if(ASOLD *4 > 5*ideal){
  1174. X        /*diff here is a negative number*/
  1175. X        diff=((4*ASOLD)-(5*ideal))/4;
  1176. X#ifdef DEBUG
  1177. X        printf("\tsplit garrison of %d men\n",diff);
  1178. X#endif DEBUG
  1179. X        free=0;
  1180. X        ASOLD-=diff;
  1181. X#ifdef DEBUG
  1182. X        if(ASOLD < 0) printf("error... subtracting %d from %d\n",diff,ASOLD);
  1183. X#endif DEBUG
  1184. X        ntn[country].tmil-=diff;
  1185. X        ntn[country].tciv+=diff;
  1186. X        sct[ntn[country].capx][ntn[country].capy].people+=diff;
  1187. X        /*I add back gold as armies get redone anyway*/
  1188. X        ntn[country].tiron += (diff* *(u_eniron + (ATYPE%100)));
  1189. X        if(magic(country,WARRIOR)==1) /* WARRIOR power */
  1190. X            ntn[country].tgold+=(diff* *(u_encost + (ATYPE%100))) / 2;
  1191. X        else ntn[country].tgold+=diff* *(u_encost + (ATYPE%100));
  1192. X    }
  1193. X#ifdef DEBUG
  1194. X    else printf("\tno action - ASOLD (%d) ~= ideal (%d)\n",ASOLD,ideal);
  1195. X    printf("\tFinal Garrison Army %d (%s) type is %s men is %d\n",armynum,ntn[country].name,*(unittype+(ATYPE)),ASOLD);
  1196. X#endif DEBUG
  1197. X
  1198. X    /*build ships and/or armies*/
  1199. X    done=FALSE;
  1200. X    ideal = ntn[country].tciv * peace / (10 * MILRATIO);
  1201. X    if(ntn[country].tgold<0) { ideal*=4; ideal/=5; }
  1202. X#ifdef DEBUG
  1203. X    printf("\t%s total military is %d -> ideal is %d\n",ntn[country].name,ntn[country].tmil,ideal);
  1204. X    check(__LINE__);
  1205. X#endif DEBUG
  1206. X    /*if < ideal build new army in the capitol - if possible*/
  1207. X    if(ntn[country].tmil < ((4*ideal)/5)) {
  1208. X        for(armynum=1;armynum<MAXARM;armynum++)
  1209. X        if((done==FALSE)&&(ASOLD==0)) {
  1210. X            done=TRUE;
  1211. X            ATYPE=A_INFANTRY;
  1212. X            ASOLD = min ((int) (ideal-ntn[country].tmil), (int) (ntn[country].tiron/ (*(u_eniron + (ATYPE%100)))));
  1213. X
  1214. X            ASOLD = min (ASOLD,sct[ntn[country].capx][ntn[country].capy].people/2);
  1215. X            ASOLD = min (ASOLD, (int) (ntn[country].tgold/ *(u_encost+(ATYPE%100))));
  1216. X            if(ASOLD>0){
  1217. X#ifdef DEBUG
  1218. Xprintf("\tnot enough soldiers - build new army %d with %d men\n",armynum,ASOLD);
  1219. X#endif DEBUG
  1220. X            ntn[country].tiron-=(ASOLD* *(u_eniron + (ATYPE%100)));
  1221. X            AXLOC= ntn[country].capx;
  1222. X            AYLOC= ntn[country].capy;
  1223. X            ntn[country].tmil += ASOLD;
  1224. X            ntn[country].tciv -= ASOLD;
  1225. X            if(magic(country,WARRIOR)==1) /* WARRIOR power */
  1226. X                ntn[country].tgold-=(ASOLD* *(u_encost + (ATYPE%100))) / 2;
  1227. X            else ntn[country].tgold-=ASOLD* *(u_encost + (ATYPE%100));
  1228. X            sct[AXLOC][AYLOC].people-=ASOLD;
  1229. X            ASTAT= DEFEND;
  1230. X            AMOVE=0;
  1231. X            }
  1232. X            else ASOLD=0;
  1233. X        }
  1234. X#ifdef DEBUG
  1235. X    check(__LINE__);
  1236. X#endif DEBUG
  1237. X    } else if(ntn[country].tmil > (6*ideal/5)){
  1238. X#ifdef DEBUG
  1239. X    check(__LINE__);
  1240. X#endif DEBUG
  1241. X        /*disband a pseudo-random army*/
  1242. X        done=FALSE;
  1243. X        diff=ntn[country].tmil-(6*ideal/5);
  1244. X#ifdef DEBUG
  1245. X        if(ASOLD < 0) printf("\ndisbanding pseudo random army of about %d men\n",diff);
  1246. X#endif DEBUG
  1247. X        for(armynum=1;armynum<MAXARM;armynum++){
  1248. X            if((done==FALSE)
  1249. X            &&(ASOLD>0)
  1250. X            &&(ATYPE!=A_MILITIA)
  1251. X            &&(sct[AXLOC][AYLOC].owner==country)
  1252. X            &&((sct[AXLOC][AYLOC].gold>4)
  1253. X                ||(sct[AXLOC][AYLOC].iron>4)
  1254. X                ||(sct[AXLOC][AYLOC].designation==DCITY))
  1255. X            &&(ASOLD<=diff)){
  1256. X#ifdef DEBUG
  1257. X                printf("\ttoo many soldiers eliminate army %d (%d men)\n",armynum,ASOLD);
  1258. X#endif DEBUG
  1259. X                diff-=ASOLD;
  1260. X                sct[AXLOC][AYLOC].people+=ASOLD;
  1261. X                ntn[country].tmil -= ASOLD;
  1262. X                ntn[country].tciv += ASOLD;
  1263. X                ASOLD=0;
  1264. X                if(diff<=50) done=TRUE;
  1265. X            }
  1266. X#ifdef DEBUG
  1267. X            if(ASOLD < 0) printf("error X... ASOLD=%d <0\n",ASOLD);
  1268. X#endif DEBUG
  1269. X        }
  1270. X    }
  1271. X#ifdef DEBUG
  1272. X    check(__LINE__);
  1273. X#endif DEBUG
  1274. X#ifdef DEBUG
  1275. X    printf("\twhew... new tmil is %d\n",ntn[country].tmil);
  1276. X#endif DEBUG
  1277. X
  1278. X    /*resize armies */
  1279. X    /*maximum npc army is 200 or tmil/20, minimum is 50*/
  1280. X    for(armynum=1;armynum<MAXARM;armynum++){
  1281. X        if((ASOLD>200)&&(ASOLD>ntn[country].tmil/20)) {
  1282. X            free=FALSE;
  1283. X            for(i=1;i<MAXARM;i++){
  1284. X                if((free==0)&&(ntn[country].arm[i].sold==0)){
  1285. X                    free=1;
  1286. X                    ASOLD/=2;
  1287. X                    ATYPE=A_INFANTRY;
  1288. X                    ntn[country].arm[i].sold  = ASOLD;
  1289. X                    ntn[country].arm[i].unittyp = A_INFANTRY;
  1290. X                    ntn[country].arm[i].smove = AMOVE;
  1291. X                    ntn[country].arm[i].stat  = DEFEND;
  1292. X                    ntn[country].arm[i].xloc  = AXLOC;
  1293. X                    ntn[country].arm[i].yloc  = AYLOC;
  1294. X                }
  1295. X            }
  1296. X        }
  1297. X    /*minimum npc army is 50, merge them*/
  1298. X        else if(ASOLD<50) {
  1299. X            free=0;
  1300. X            for(i=1;i<MAXARM;i++){
  1301. X                if((ntn[country].arm[i].sold>0)
  1302. X                &&(ntn[country].arm[i].xloc==AXLOC)
  1303. X                &&(ntn[country].arm[i].yloc==AYLOC)
  1304. X                &&(ntn[country].arm[i].unittyp==ATYPE)
  1305. X                &&(i!=armynum)&&(free==0)){
  1306. X                    free=1;
  1307. X                    ntn[country].arm[i].sold += ASOLD;
  1308. X                    ntn[country].arm[i].unittyp=A_INFANTRY;
  1309. X                    ASOLD=0;
  1310. X                }
  1311. X            }
  1312. X        }
  1313. X    }
  1314. X#ifdef DEBUG
  1315. X    check(__LINE__);
  1316. X#endif DEBUG
  1317. X
  1318. X    /* assure that militia unit resides in each city */
  1319. X        for(armynum=0;armynum<MAXARM;armynum++)
  1320. X        if((ASOLD>0)&&(ATYPE==A_MILITIA)){
  1321. X#ifdef DEBUG
  1322. X        printf("\t\t%s army %d (now %d men - populace %d)\n",unittype[ATYPE],armynum,ASOLD,sct[AXLOC][AYLOC].people);
  1323. X#endif DEBUG
  1324. X            if((sct[AXLOC][AYLOC].designation!=DCITY)
  1325. X            &&(sct[AXLOC][AYLOC].designation!=DCAPITOL)){
  1326. X#ifdef DEBUG
  1327. X                printf("\teliminating %s army %d as %d %d is des:%c alt:%c own:%d\n",unittype[ATYPE],armynum,AXLOC,AYLOC,sct[AXLOC][AYLOC].designation,sct[AXLOC][AYLOC].altitude,sct[AXLOC][AYLOC].owner);
  1328. X#endif DEBUG
  1329. X                if(sct[AXLOC][AYLOC].owner == country)
  1330. X                sct[AXLOC][AYLOC].people+=ASOLD;
  1331. X                else
  1332. X                sct[ntn[country].capx][ntn[country].capy].people+=ASOLD;
  1333. X                ASOLD=0;
  1334. X            }
  1335. X        }
  1336. X
  1337. X    if(ntn[country].tgold > 0)
  1338. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1339. X    if((sct[x][y].owner==country)
  1340. X    &&((sct[x][y].designation==DCITY)||(sct[x][y].designation==DCAPITOL))){
  1341. X        free=FALSE;
  1342. X        for(armynum=0;armynum<MAXARM;armynum++){
  1343. X            if((ASOLD>0)
  1344. X            &&(AXLOC==x)&&(AYLOC==y)
  1345. X            &&(ATYPE==A_MILITIA)) {
  1346. X                free=TRUE;
  1347. X                break;
  1348. X            }
  1349. X        }
  1350. X        if(free==FALSE) {     /* draft a new militia army */
  1351. X            for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD==0){
  1352. X                ATYPE=A_MILITIA;
  1353. X                AXLOC=x;
  1354. X                AYLOC=y;
  1355. X                free=TRUE;
  1356. X                break;
  1357. X            }
  1358. X        }
  1359. X        if((free==TRUE)) {
  1360. X            /* want to add ideal troops */
  1361. X            ideal = sct[x][y].people/MILINCITY - ASOLD;
  1362. X            ideal = min(ideal, 250);
  1363. X            if(ideal>0){
  1364. X            if(magic(country,WARRIOR)==TRUE){ /* WARRIOR power */
  1365. X                ntn[country].tgold-=
  1366. X                    (ideal* *(u_encost+ATYPE))/2;
  1367. X            } else {
  1368. X                ntn[country].tgold-=
  1369. X                    ideal* *(u_encost + ATYPE);
  1370. X            }
  1371. X            }
  1372. X            ASOLD+=ideal;
  1373. X            ASTAT=GARRISON;
  1374. X#ifdef DEBUG
  1375. X        if(ATYPE!=A_MILITIA) printf("ERROR - NOT MILITIA\n");
  1376. X        printf("\tadding %d troops to %s army %d (now %d men - populace %d)\n",ideal,unittype[ATYPE],armynum,ASOLD,sct[x][y].people);
  1377. X#endif DEBUG
  1378. X        }
  1379. X    }
  1380. X#ifdef DEBUG
  1381. X    check(__LINE__);
  1382. X#endif DEBUG
  1383. X
  1384. X    /* if archer power - all units are archers */
  1385. X    if(magic(country,ARCHER)==1)
  1386. X    for(armynum=1;armynum<MAXARM;armynum++)
  1387. X        if((ASOLD>0)&&(ATYPE!=A_MILITIA)) ATYPE=A_ARCHER;
  1388. X}
  1389. X
  1390. Xvoid
  1391. Xgetdstatus()
  1392. X{
  1393. X    int x,oldstat[MAXNTN];
  1394. X
  1395. X    if(ntn[country].active<=1) return;
  1396. X
  1397. X    for(x=1;x<MAXNTN;x++) {
  1398. X        oldstat[x] = ntn[country].dstatus[x];
  1399. X        /*if they at war with you go to war with them*/
  1400. X        if(ntn[x].dstatus[country]>=WAR) {
  1401. X            if(ntn[country].dstatus[x]<WAR)
  1402. X            fprintf(fnews,"2.\tnation %s returns %s's declaration of war\n",ntn[country].name,ntn[x].name);
  1403. X
  1404. X            ntn[country].dstatus[x]=WAR;
  1405. X        } else
  1406. X        if((ntn[country].dstatus[x]!=UNMET)
  1407. X        &&(ntn[country].dstatus[x]!=JIHAD)
  1408. X        &&(ntn[country].dstatus[x]!=CONFEDERACY)
  1409. X        &&(ntn[country].active!=1)){
  1410. X            if((ntn[x].tmil>4*ntn[country].tmil)
  1411. X            &&(ntn[x].score>4*ntn[country].score)){
  1412. X                if(rand()%3==0)  {
  1413. X                    ntn[country].dstatus[x]=WAR;
  1414. X                } else if(rand()%8==0)  {
  1415. X                    ntn[country].dstatus[x]=JIHAD;
  1416. X                }
  1417. X            }
  1418. X            /*if 2* mil and 2* score then not like them*/
  1419. X            else if((ntn[x].tmil>2*ntn[country].tmil)
  1420. X            &&(ntn[x].score>2*ntn[country].score)){
  1421. X                if((ntn[country].dstatus[x]!=WAR)
  1422. X                &&(ntn[x].race!=ntn[country].race)){
  1423. X                    if(rand()%3==0)
  1424. X                        ntn[country].dstatus[x]++;
  1425. X                }
  1426. X            }
  1427. X            /*adjust based on your status with them*/
  1428. X            if((ntn[country].dstatus[x]==WAR)
  1429. X            &&(ntn[x].dstatus[country]<WAR))
  1430. X                if(rand()%3==0) ntn[country].dstatus[x]--;
  1431. X
  1432. X            if((ntn[country].dstatus[x]<WAR)
  1433. X            &&(ntn[country].dstatus[x]>ALLIED)){
  1434. X                if(ntn[x].dstatus[country]>1+ntn[country].dstatus[x]){
  1435. X                    if(rand()%3==0)
  1436. X                        ntn[country].dstatus[x]++;
  1437. X                }
  1438. X                else
  1439. X                if(ntn[x].dstatus[country]+1<ntn[country].dstatus[x]){
  1440. X                    if(rand()%3==0)
  1441. X                        ntn[country].dstatus[x]--;
  1442. X                }
  1443. X                if(ntn[x].race==ntn[country].race)
  1444. X                    if(rand()%3==0)
  1445. X                        ntn[country].dstatus[x]--;
  1446. X            }
  1447. X            if(rand()%6==0) {
  1448. X                if(ntn[country].dstatus[x]!=JIHAD)
  1449. X                    ntn[country].dstatus[x]++;
  1450. X            }
  1451. X            else if((rand()%5==0)
  1452. X            &&(ntn[country].dstatus[x]!=CONFEDERACY)) {
  1453. X                ntn[country].dstatus[x]--;
  1454. X            }
  1455. X        }
  1456. X    }
  1457. X
  1458. X    for(x=1;x<MAXNTN;x++)
  1459. X    if(ntn[x].active>1){
  1460. X        if((rand()%5==0)
  1461. X        &&(ntn[x].dstatus[country]==WAR)
  1462. X        &&(ntn[country].dstatus[x]==WAR)) {
  1463. X            ntn[x].dstatus[country]=HOSTILE;
  1464. X            ntn[country].dstatus[x]=HOSTILE;
  1465. X            fprintf(fnews,"2.\tnation %s and %s announce ceasefire\n",ntn[country].name,ntn[x].name);
  1466. X        } else if((oldstat[x]==WAR)&&(ntn[country].dstatus[x]==WAR)){
  1467. X            fprintf(fnews,"2.\tnation %s stays at war with %s\n",ntn[country].name,ntn[x].name);
  1468. X        } else if((oldstat[x]<WAR)&&(ntn[country].dstatus[x]==WAR)){
  1469. X            fprintf(fnews,"2.\tnation %s goes to war with %s\n",ntn[country].name,ntn[x].name);
  1470. X        } else if((oldstat[x]!=JIHAD)&&(ntn[country].dstatus[x]==JIHAD)){
  1471. X            fprintf(fnews,"2.\tnation %s announces a jihad with %s\n",ntn[country].name,ntn[x].name);
  1472. X        }
  1473. X    }
  1474. X}
  1475. X
  1476. Xint
  1477. Xnationrun()
  1478. X{
  1479. X    int goldthresh,ironthresh,citythresh;
  1480. X    int armynum,loop;
  1481. X    int x,y,i;
  1482. X    long zz;
  1483. X
  1484. X#ifdef DEBUG
  1485. X    check(__LINE__);
  1486. X#endif DEBUG
  1487. X    prep(country);
  1488. X
  1489. X    /* is there an error*/
  1490. X    if((sct[ntn[country].capx][ntn[country].capy].owner==country)
  1491. X    &&(sct[ntn[country].capx][ntn[country].capy].designation!=DCAPITOL)){
  1492. X        sct[ntn[country].capx][ntn[country].capy].designation=DCAPITOL;
  1493. X    }
  1494. X
  1495. X    getdstatus();
  1496. X
  1497. X    /*move units */
  1498. X    /*are they at war with any normal countries*/
  1499. X    peace=0;
  1500. X    for(i=1;i<MAXNTN;i++) if(ntn[country].dstatus[i]>peace)
  1501. X        peace=ntn[country].dstatus[i];
  1502. X
  1503. X#ifdef DEBUG
  1504. X    check(__LINE__);
  1505. X#endif DEBUG
  1506. X    if(peace<WAR){
  1507. X        peace=8;
  1508. X        pceattr();
  1509. X    } else {
  1510. X    /*if war then attack &/or expand */
  1511. X        peace=12;
  1512. X        /*are they attacking or defending */
  1513. X        if(ntn[country].tmil==0) defattr();
  1514. X        else for(x=0;x<MAXNTN;x++) if(ntn[country].dstatus[x]>HOSTILE){
  1515. X            if(100*(ntn[country].tmil*(ntn[country].aplus+100))/((ntn[country].tmil*(ntn[country].aplus+100))+(ntn[x].tmil*(ntn[x].dplus+100)))>rand()%100){
  1516. X                /*attacker*/
  1517. X                for(armynum=1;armynum<MAXARM;armynum++)
  1518. X                    if((ASOLD>0)&&(ATYPE!=A_MILITIA))
  1519. X                        ASTAT=ATTACK;
  1520. X                atkattr();
  1521. X            }
  1522. X            /*defender*/
  1523. X            else {
  1524. X                for(armynum=1;armynum<MAXARM;armynum++)
  1525. X                    if((ASOLD>0)&&(ATYPE!=A_MILITIA)){
  1526. X                        if(ASOLD<350) ASTAT=DEFEND;
  1527. X                        else ASTAT=ATTACK;
  1528. X                    }
  1529. X                defattr();
  1530. X            }
  1531. X        }
  1532. X    }
  1533. X#ifdef DEBUG
  1534. X    check(__LINE__);
  1535. X#endif DEBUG
  1536. X    for(armynum=1;armynum<MAXARM;armynum++)
  1537. X        if((ASOLD!=0)
  1538. X        &&(ATYPE!=A_MILITIA)) armymove(armynum);
  1539. X
  1540. X    /* INTELLIGENT SECTOR REDESIGNATION */
  1541. X    if(ntn[country].active!=1) {        /* no pc's */
  1542. X        goldthresh=4;
  1543. X        ironthresh=4;
  1544. X        citythresh=10;
  1545. X        for(loop=1;loop<5;loop++) {
  1546. X#ifdef DEBUG
  1547. X            printf("\tnpcredes(): country %s, food %ld gold %d, iron %d, city %d\n",ntn[country].name,spread.food,goldthresh,ironthresh,citythresh);
  1548. X#endif DEBUG
  1549. X
  1550. X            for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1551. X                if((sct[x][y].owner==country)
  1552. X                &&(is_habitable(x,y)))
  1553. X                n_redes(x,y,goldthresh,ironthresh,citythresh);
  1554. X
  1555. X            spreadsheet(country);
  1556. X
  1557. X            if(spread.food < spread.civilians * 2L) {
  1558. X                goldthresh++;
  1559. X                ironthresh++;
  1560. X                citythresh--;
  1561. X            } else if(spread.food > spread.civilians * 3L) {
  1562. X                if(rand()%2==0) goldthresh--;
  1563. X                else ironthresh--;
  1564. X                if(goldthresh==0) goldthresh=1;
  1565. X                if(ironthresh==0) ironthresh=1;
  1566. X                citythresh++;
  1567. X            }
  1568. X            else break;
  1569. X        }
  1570. X    }
  1571. X
  1572. X    /*build forts in any cities*/
  1573. X    if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1574. X        if(((sct[x][y].designation==DCITY)
  1575. X            ||(sct[x][y].designation==DCAPITOL))
  1576. X            &&(sct[x][y].owner==country)
  1577. X            &&(sct[x][y].fortress<10)
  1578. X            &&(ntn[country].tgold>10000)
  1579. X            &&(rand()%5==0)
  1580. X            &&(sct[x][y].fortress<(sct[x][y].people%1000)))
  1581. X                sct[x][y].fortress++;
  1582. X#ifdef DEBUG
  1583. X    check(__LINE__);
  1584. X#endif DEBUG
  1585. X    /*redo mil*/
  1586. X    if(ntn[country].active!=1) redomil();
  1587. X#ifdef DEBUG
  1588. X    check(__LINE__);
  1589. X#endif DEBUG
  1590. X
  1591. X    /*buy new powers and/or new weapons*/
  1592. X    if(getmgkcost(M_MIL,country) < getmgkcost(M_CIV,country)){
  1593. X        if(ntn[country].jewels > getmgkcost(M_MIL,country)) {
  1594. X            ntn[country].jewels-=getmgkcost(M_MIL,country);
  1595. X            if((zz=getmagic(M_MIL))!=0){
  1596. X                fprintf(fnews,"1.\tnation %s gets combat power number %d\n",ntn[country].name,zz);
  1597. X                printf("\tnation %s gets combat power number %d\n",ntn[country].name,zz);
  1598. X                exenewmgk(zz);
  1599. X            } else if((zz=getmagic(M_MIL))!=0){
  1600. X                fprintf(fnews,"1.\tnation %s gets combat power number %d\n",ntn[country].name,zz);
  1601. X                printf("\tnation %s gets combat power number %d\n",ntn[country].name,zz);
  1602. X                exenewmgk(zz);
  1603. X            }
  1604. X            else    ntn[country].jewels+=getmgkcost(M_MIL,country);
  1605. X        }
  1606. X    } else {
  1607. X        if(ntn[country].jewels > getmgkcost(M_CIV,country)) {
  1608. X            ntn[country].jewels-=getmgkcost(M_CIV,country);
  1609. X            if((zz=getmagic(M_CIV))!=0){
  1610. X                fprintf(fnews,"1.\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
  1611. X                printf("\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
  1612. X                exenewmgk(zz);
  1613. X            }
  1614. X            else if((zz=getmagic(M_CIV))!=0){
  1615. X                fprintf(fnews,"1.\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
  1616. X                printf("\tnation %s gets civilian power number %d\n",ntn[country].name,zz);
  1617. X                exenewmgk(zz);
  1618. X            }
  1619. X            else    ntn[country].jewels+=getmgkcost(M_CIV,country);
  1620. X        }
  1621. X    }
  1622. X
  1623. X#ifdef DEBUG
  1624. X    check(__LINE__);
  1625. X#endif DEBUG
  1626. X    if(magic(country,VAMPIRE)!=1) {
  1627. X        i=0;
  1628. X        if(magic(country,WARLORD)==1) i=30;
  1629. X        else if(magic(country,CAPTAIN)==1) i=20;
  1630. X        else if(magic(country,WARRIOR)==1) i=10;
  1631. X        x = max ( ntn[country].aplus-i, 10 ) / 10;
  1632. X        /* SHOULD USE spread.iron but it didnt work right */
  1633. X        if(ntn[country].tiron >  3 * IRONORE * ntn[country].tmil*x*x){
  1634. X            ntn[country].aplus+=1;
  1635. X            ntn[country].dplus+=1;
  1636. X            ntn[country].tiron-=2*IRONORE*ntn[country].tmil*x*x;
  1637. X            printf("\tnation %s buys +1 percent attack and defence\n",ntn[country].name);
  1638. X        }
  1639. X    }
  1640. X}
  1641. X
  1642. X/* make sectors of those with whom you are peaceful attr = 1 */
  1643. Xn_atpeace()
  1644. X{
  1645. X    register int x,y;
  1646. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
  1647. X        if((sct[x][y].owner!=0)
  1648. X        &&(ntn[country].dstatus[sct[x][y].owner]<WAR)
  1649. X        &&(abs(x-ntn[country].capx)>2)
  1650. X        &&(abs(y-ntn[country].capy)>2))
  1651. X            attr[x][y]=1;
  1652. X}
  1653. X
  1654. X/* you are too far from capitol */
  1655. Xn_toofar()
  1656. X{
  1657. X    register int x,y;
  1658. X    for(x=ntn[country].capx+NPCTOOFAR;x<MAPX;x++)
  1659. X        for(y=0;y<MAPY;y++) if(ONMAP)
  1660. X            attr[x][y]=1;
  1661. X    for(y=ntn[country].capy+NPCTOOFAR;y<MAPY;y++)
  1662. X        for(x=0;x<MAPY;x++) if(ONMAP)
  1663. X            attr[x][y]=1;
  1664. X    for(x=0;x<ntn[country].capx-NPCTOOFAR;x++)
  1665. X        for(y=0;y<MAPY;y++) if(ONMAP)
  1666. X            attr[x][y]=1;
  1667. X    for(y=0;y<ntn[country].capy-NPCTOOFAR;y++)
  1668. X        for(x=0;x<MAPY;x++) if(ONMAP)
  1669. X            attr[x][y]=1;
  1670. X}
  1671. X
  1672. X/* take undefended land */
  1673. Xn_unowned()
  1674. X{
  1675. X    register int x,y;
  1676. X    int dist;
  1677. X
  1678. X    /* around capitol */
  1679. X    for(x=ntn[country].capx-4;x<=ntn[country].capx+4;x++){
  1680. X        for(y=ntn[country].capy-4;y<=ntn[country].capy+4;y++){
  1681. X            if((ONMAP)&&(sct[x][y].owner==0)) {
  1682. X                /* find distance btwn x,y and cap */
  1683. X                dist=abs(x-ntn[country].capx)+abs(y,ntn[country].capy);
  1684. X                if(dist<10) attr[x][y]+= 500 - 50*dist;
  1685. X            }
  1686. X        }
  1687. X    }
  1688. X
  1689. X    for(x=0;x<MAPX;x++) {
  1690. X        for(y=0;y<MAPY;y++) {
  1691. X            /*add to attractiveness for unowned sectors*/
  1692. X            if(sct[x][y].owner == 0) {
  1693. X                attr[x][y]+=100;
  1694. X            } else    {
  1695. X            if(sct[x][y].owner == NNOMAD)
  1696. X                attr[x][y]+=25;
  1697. X            }
  1698. X        }
  1699. X    }
  1700. X    if(is_habitable(x,y) == 0) attr[x][y] /= 5;
  1701. X}
  1702. Xvoid
  1703. Xn_defend(natn)
  1704. Xregister short natn;
  1705. X{
  1706. X    int x,y;
  1707. X
  1708. X    /* add 1/10th of soldiers in sector */
  1709. X    for(x=1;x<MAXARM;x++) if(ntn[natn].arm[x].sold > 0)
  1710. X        if(sct[ntn[natn].arm[x].xloc][ntn[natn].arm[x].yloc].owner==country)
  1711. X            attr[ntn[natn].arm[x].xloc][ntn[natn].arm[x].yloc] +=
  1712. X                ntn[natn].arm[x].sold/10;
  1713. X
  1714. X    /*plus 80 if near your capitol */
  1715. X    for(x=ntn[country].capx-1;x<=ntn[country].capy+1;x++){
  1716. X        for(y=ntn[country].capy-1;y<=ntn[country].capy+1;y++){
  1717. X            if(ONMAP) attr[x][y]+=80;
  1718. X        }
  1719. X    }
  1720. X
  1721. X    /*plus based on defensive value*/
  1722. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
  1723. X        if(movecost[x][y]==1) attr[x][y] += 50;
  1724. X        else if(movecost[x][y]<=3) attr[x][y] += 20;
  1725. X        else if(movecost[x][y]<=5) attr[x][y] += 10;
  1726. X
  1727. X        if((sct[x][y].designation==DCITY)
  1728. X        &&((sct[x][y].owner==country)||(sct[x][y].owner==natn))){
  1729. X            attr[x][y] += 50;
  1730. X        }
  1731. X    }
  1732. X}
  1733. X
  1734. Xvoid
  1735. Xn_attack(nation)
  1736. Xregister short nation;
  1737. X{
  1738. X    register int x,y;
  1739. X
  1740. X    /*plus 40 if next to their capitol */
  1741. X    for(x=ntn[nation].capx-1;x<=ntn[nation].capy+1;x++){
  1742. X        for(y=ntn[nation].capy-1;y<=ntn[nation].capy+1;y++){
  1743. X            if((sct[x][y].owner==nation)&&(ONMAP))
  1744. X                attr[x][y]+=40;
  1745. X        }
  1746. X    }
  1747. X
  1748. X    /*plus 100 if on their capitol*/
  1749. X    attr[ntn[nation].capx][ntn[nation].capy]+=100;
  1750. X}
  1751. X
  1752. X/* +100 if undefended sectors of nation, +60 if not */
  1753. Xvoid
  1754. Xn_undefended( nation )
  1755. X{
  1756. X    register int x,y;
  1757. X    for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==nation){
  1758. X        if(is_habitable(x,y) == 0) {
  1759. X            attr[x][y] += 30;
  1760. X        } else if(occ[x][y]==0) {
  1761. X            attr[x][y]+=100;
  1762. X        } else {
  1763. X            attr[x][y]+=60;
  1764. X        }
  1765. X    }
  1766. X}
  1767. X
  1768. X/* +60 if between two capitols */
  1769. Xvoid
  1770. Xn_between(nation)
  1771. Xint nation;
  1772. X{
  1773. X    int x1,x2,y1,y2,x,y;
  1774. X
  1775. X    /*plus if strategic blocking sector*/
  1776. X
  1777. X    /*+60 if between the two capitol*/
  1778. X    if (ntn[nation].capx < ntn[country].capx){
  1779. X        x1=ntn[nation].capx;
  1780. X        x2=ntn[country].capx;
  1781. X    } else {
  1782. X        x1=ntn[country].capx;
  1783. X        x2=ntn[nation].capx;
  1784. X    }
  1785. X    if (ntn[nation].capy < ntn[country].capy){
  1786. X        y1=ntn[nation].capy;
  1787. X        y2=ntn[country].capy;
  1788. X    }
  1789. X    else {
  1790. X        y1=ntn[country].capy;
  1791. X        y2=ntn[nation].capy;
  1792. X    }
  1793. X
  1794. X    for(x=x1;x<=x2;x++) for(y=y1;y<=y2;y++) {
  1795. X        if(ONMAP) attr[x][y]+=60;
  1796. X    }
  1797. X}
  1798. X
  1799. X/* if in jeopardy, move to survive
  1800. X *    if within two of cap add 1/5th of men
  1801. X *    if on cap and war and 2x your garrison go jihad and + 1/2 men
  1802. X */
  1803. Xvoid
  1804. Xn_survive()
  1805. X{
  1806. X    register struct army        *aptr;
  1807. X    int nation,armynum;
  1808. X
  1809. X    if(sct[ntn[country].capy][ntn[country].capy].owner!=country){
  1810. X        attr[ntn[country].capy][ntn[country].capy]=1000;
  1811. X    }
  1812. X
  1813. X    /*defend your capitol if occupied, +50 more if with their army*/
  1814. X    for(nation=1;nation<MAXNTN;nation++)
  1815. X    if((ntn[nation].active != 0)
  1816. X    &&((ntn[nation].dstatus[country]>=WAR)
  1817. X    ||(ntn[country].dstatus[nation]>=WAR))){
  1818. X        for(armynum=1;armynum<MAXARM;armynum++)
  1819. X        if(ntn[nation].arm[armynum].sold > 0) {
  1820. X
  1821. X            aptr = &(ntn[nation].arm[armynum]);
  1822. X
  1823. X            if((aptr->xloc==ntn[nation].capx)
  1824. X            &&(aptr->yloc==ntn[nation].capy)){
  1825. X                if(aptr->sold>2*ntn[country].arm[0].sold){
  1826. X                    attr[aptr->xloc][aptr->yloc]+=
  1827. X                        aptr->sold/2;
  1828. X                } else {
  1829. X                    attr[aptr->xloc][aptr->yloc]+=
  1830. X                        aptr->sold/5;
  1831. X                }
  1832. X            }
  1833. X            else if((aptr->xloc<=ntn[nation].capx+2)
  1834. X            &&(aptr->xloc>=ntn[nation].capx-2)
  1835. X            &&(aptr->yloc<=ntn[nation].capy+2)
  1836. X            &&(aptr->yloc>=ntn[nation].capy-2)){
  1837. X                attr[aptr->xloc][aptr->yloc]+=aptr->sold/5;
  1838. X
  1839. X            }
  1840. X        }
  1841. X    }
  1842. X}
  1843. X
  1844. Xvoid
  1845. Xdefattr()
  1846. X{
  1847. X    int nation;
  1848. X
  1849. X    n_unowned();
  1850. X
  1851. X    for(nation=1;nation<MAXNTN;nation++)
  1852. X    if((ntn[nation].active!=0)&&(ntn[country].dstatus[nation]>=WAR)) {
  1853. X        n_defend(nation);
  1854. X        n_between(nation);
  1855. X        n_undefended(nation);
  1856. X    }
  1857. X
  1858. X    n_toofar();
  1859. X    n_survive();
  1860. X}
  1861. X
  1862. X/*calculate attractiveness of attacking sectors*/
  1863. Xvoid
  1864. Xatkattr()
  1865. X{
  1866. X    int nation;
  1867. X
  1868. X    n_unowned();
  1869. X
  1870. X    /*adjust for each nation that you are at war with*/
  1871. X    for(nation=1;nation<MAXNTN;nation++)
  1872. X        if(ntn[country].active!=0)
  1873. X            if(ntn[country].dstatus[nation]==WAR) {
  1874. X                n_between(nation);
  1875. X                n_undefended(nation);
  1876. X                n_attack(nation);
  1877. X            } else if(ntn[country].dstatus[nation]==JIHAD) {
  1878. X                n_attack(nation);
  1879. X                n_attack(nation);
  1880. X                n_between(nation);
  1881. X                n_undefended(nation);
  1882. X                n_attack(nation);
  1883. X                n_between(nation);
  1884. X                n_undefended(nation);
  1885. X                n_attack(nation);
  1886. X            }
  1887. X
  1888. X    n_toofar();
  1889. X    n_survive();
  1890. X}
  1891. X
  1892. X/*calculate attractiveness when at peace*/
  1893. Xint
  1894. Xpceattr()
  1895. X{
  1896. X    n_unowned();
  1897. X    n_atpeace();
  1898. X    n_toofar();
  1899. X    n_survive();
  1900. X}
  1901. X#endif
  1902. X
  1903. X#ifdef DEBUG
  1904. Xcheck(line)
  1905. Xint line;
  1906. X{
  1907. X    int armynum;
  1908. X    for(armynum=0;armynum<MAXARM;armynum++)
  1909. X        if(ASOLD<0) {
  1910. X        printf("ERROR: line %d army %d nation %s soldier %d\n",line,armynum,ntn[country].name,ASOLD);
  1911. X        ASOLD=0;
  1912. X        }
  1913. X        if((AXLOC>MAPX)||(AYLOC>MAPY)){
  1914. X        printf("CHECK ERROR: line %d army %d nation %s loc %d %d\n",line,armynum,ntn[country].name,AXLOC,AYLOC);
  1915. X        }
  1916. X    if(ntn[country].tiron < 0L)
  1917. X        printf("ERROR: line %d nation %s iron is %ld\n",line,ntn[country].name,ntn[country].tiron);
  1918. X    if(ntn[country].tfood < 0L)
  1919. X        printf("ERROR: line %d nation %s food is %ld\n",line,ntn[country].name,ntn[country].tfood);
  1920. X    if(ntn[country].jewels < 0L)
  1921. X        printf("ERROR: line %d nation %s jewels is %ld\n",line,ntn[country].name,ntn[country].jewels);
  1922. X}
  1923. X#endif DEBUG
  1924. END_OF_npc.c
  1925. if test 28401 -ne `wc -c <npc.c`; then
  1926.     echo shar: \"npc.c\" unpacked with wrong size!
  1927. fi
  1928. # end of overwriting check
  1929. fi
  1930. echo shar: End of archive 2 \(of 8\).
  1931. cp /dev/null ark2isdone
  1932. MISSING=""
  1933. for I in 1 2 3 4 5 6 7 8 ; do
  1934.     if test ! -f ark${I}isdone ; then
  1935.     MISSING="${MISSING} ${I}"
  1936.     fi
  1937. done
  1938. if test "${MISSING}" = "" ; then
  1939.     echo You have unpacked all 8 archives.
  1940.     rm -f ark[1-9]isdone
  1941. else
  1942.     echo You still need to unpack the following archives:
  1943.     echo "        " ${MISSING}
  1944. fi
  1945. ##  End of shell archive.
  1946. exit 0
  1947.